﻿using System;
using System.Collections.Generic;
using System.Linq;
using Sumen.Model.Model;

namespace Sumen.Business.Presenter.Actor
{
    public class EmployeePresenter
    {


        public int Update(object pObjectValue, object pId)
        {
            using (sumenEntitiesSystem objEntities = new sumenEntitiesSystem())
            {
                employee newEmployee = pObjectValue as employee;

                long user = Convert.ToInt64(pId);
                employee oldEmployee = objEntities.employees.FirstOrDefault(p => p.Emp_Username == user);
                oldEmployee.Emp_Username = newEmployee.Emp_Username;
                oldEmployee.Emp_FullName = newEmployee.Emp_FullName;
                oldEmployee.Emp_Phone = newEmployee.Emp_Phone;
                oldEmployee.Emp_Address = newEmployee.Emp_Address;
                oldEmployee.Emp_Email = newEmployee.Emp_Email;
                oldEmployee.Emp_Contact = newEmployee.Emp_Contact;
                oldEmployee.Emp_Actived = newEmployee.Emp_Actived;
                oldEmployee.Emp_Avatar = newEmployee.Emp_Avatar;
                oldEmployee.Emp_Birthday = newEmployee.Emp_Birthday;
                oldEmployee.Emp_CMND = newEmployee.Emp_CMND;
                oldEmployee.Emp_Gender = newEmployee.Emp_Gender;
                oldEmployee.Emp_NgayTuyenDung = newEmployee.Emp_NgayTuyenDung;
                oldEmployee.Emp_ThongTinSucKhoe = newEmployee.Emp_ThongTinSucKhoe;
                oldEmployee.Emp_MaSoThue = newEmployee.Emp_MaSoThue;
                oldEmployee.Emp_City = newEmployee.Emp_City;
                oldEmployee.Emp_District = newEmployee.Emp_District;
                return objEntities.SaveChanges();
            }
        }

        public int Add(object pObjectValue)
        {
            using (sumenEntitiesSystem objEntities = new sumenEntitiesSystem())
            {
                employee newEmployee = pObjectValue as employee;
                objEntities.employees.Add(newEmployee);
                return objEntities.SaveChanges();
            }
        }

        public int Delete(object pObjectValue)
        {
            using (sumenEntitiesSystem objEntities = new sumenEntitiesSystem())
            {
                long user = Convert.ToInt64(pObjectValue);
                objEntities.employees.Remove(
                    objEntities.employees.FirstOrDefault(p => p.Emp_Username == user));
                return objEntities.SaveChanges();
            }
        }

        public ICollection<employee> GetAll()
        {
            using (sumenEntitiesSystem objEntities = new sumenEntitiesSystem())
            {
                return objEntities.employees.ToList();
            }
        }

        public employee GetById(object pId)
        {
            using (sumenEntitiesSystem objEntities = new sumenEntitiesSystem())
            {
                long user = Convert.ToInt64(pId);
                return objEntities.employees.FirstOrDefault(p => p.Emp_Username == user);
            }
        }


    }
}
